import { createStore } from 'vuex'

export default createStore({
  state: {
    //获取本地的user
    user: JSON.parse(window.localStorage.getItem("user") || "{}")
  },
  mutations: {
    login(state, user) {
      state.user = user
      //登录后存在本地
      window.localStorage.setItem("user", JSON.stringify(user))
    },
    logout(state) {
      state.user = {}
      //移除user
      window.localStorage.removeItem("user")
    }
  },
  actions: {
  },
  modules: {
  }
})
